"""
1.使用面向对象的思想按照要求实现下面的功能，注意类和对象的使用

学生类Student:
		属性:学号，姓名，年龄，性别，成绩

班级类 Grade:
 		属性:班级名称，班级中的学生 【使用列表存储学生】

		方法:
			1.查看该班级中的所有学生的信息
			2.查看指定学号的学生信息
			3.查看班级中成绩不及格的学生信息
			4.将班级中的学生按照成绩降序排序

"""



class Student():
    __slots__ = ('st_no', 'name','age','sex','score')
    def __init__(self,st_no,name,age,sex,score):
        self.st_no = st_no
        self.name = name
        self.age = age
        self.sex = sex
        self.score = score

    def __repr__(self):
        return f"学生信息:{self.st_no},{self.name},{self.age},{self.sex},{self.score}"

class Grade():
    def __init__(self,grade_name):
        self.grade_name = grade_name
        self.students_list = []

    def __repr__(self):
        return f"{self.grade_name}所有学生:{self.students_list}"

    def add_student(self,student):
            self.students_list.append(student)

    def show_student_by_st_no(self,sid):
        print(f"寻找学号{sid}的学生信息")
        stno_list = [stu for stu in self.students_list if stu.st_no == sid ]
        print(stno_list)


    def show_fail_student(self):
        fail_list = [stu for stu in self.students_list if stu.score < 60 ]
        print(fail_list)

    def show_score_desc(self):
        self.students_list.sort(key=lambda x: x.score, reverse=True)
        print(self.students_list)



def main():
    s1 = Student('1003', '小明', 19, "male", 88)
    s2 = Student('1001', '小王', 17, "female", 100)
    s3 = Student('1005', '小李', 19, "male", 56)
    s4 = Student('1006', '小张', 20, "female", 99)
    s5 = Student('1002', '小赵', 18, "male", 60)
    Grade1 = Grade("3班")
    Grade1.add_student(s1)
    Grade1.add_student(s2)
    Grade1.add_student(s3)
    Grade1.add_student(s4)
    Grade1.add_student(s5)
    print(f"目前是{Grade1.grade_name}查询页面".center(50,"="))
    while True:
        print("1.查看该班级中的所有学生的信息")
        print("2.查看指定学号的学生信息")
        print("3.查看班级中成绩不及格的学生信息")
        print("4.将班级中的学生按照成绩降序排序")
        print("任意键退出")
        fun = input("根据提示输入对应序号进行业务:")

        if fun == "1":
            print(Grade1)
        elif fun == "2":
            Grade1.show_fail_student()
        elif fun == "3":
            sid = input("输入学号:")
            Grade1.show_student_by_st_no(sid)
        elif fun == "4":
            Grade1.show_score_desc()
        else:
            break

if __name__ == '__main__':
    main()